const BaseController = require('./BaseController.js');

class MenuController extends BaseController {
  // 菜单列表
  async menu_list(){
    const { ctx } = this
    let params = await this.getParams(ctx)
    let result = await ctx.service.menu.list(params)
    this.showSuccess(result)
  }

  // 创建菜单
  async menu_create(){
    const { ctx } = this
    let params = await this.getParams(ctx)
    let result = await ctx.service.menu.create(params)
    if(result){
      this.showSuccess(result)
    }else{
      this.ApiException('英文标识不能重复')
    }
  }

  // 编辑菜单
  async menu_edit(){
    const { ctx } = this
    let params = await this.getParams(ctx)
    let result = await ctx.service.menu.edit(params)
    if(result){
      this.showSuccess(result)
    }else{
      this.ApiException('英文标识不能重复')
    }
  }

  // 删除菜单
  async menu_delete(){
    const { ctx } = this
    let params = await this.getParams(ctx)
    let result = await ctx.service.menu.deleteItem(params)
    if(result.state){
      this.showSuccess(result.msg)
    }else{
      this.ApiException(result.msg)
    }
  }

}

module.exports = MenuController;